from datetime import datetime
from sumolib import checkBinary
import redis
from loguru import logger
from pathlib import Path


class SimulationConfig:
    def __init__(self, env, region):
        #检查是否有logs文件夹，没有则创建
        log_dir = Path("logs")
        log_dir.mkdir(exist_ok=True)
        self.log_file = log_dir / f"{region}_{env}.log"
        #根据时间来命名log名字。
        # self.log_file = r"logs/{time:YYYY-MM-DD}.log"
        self.sumoBinary = checkBinary("sumo")
        self.gui_settings_file = 'viewsettings.xml'
        self.SIMULATION_START = datetime.now().strftime("%Y%m%d-%H:%M:%S")
        self.truck_start_type = "car_start__stop_list"
        self.truck_stop_type = ["rest_stop_lane", "car_start__stop_list"]
        self.TRUCK_STOP_TIME = -1073741824.0
        self.BATCH_SIZE = 50
        self.INTERVAL = 10
        if env == 'dev':
            ##SUMO windows version 1.21.0.
            self.pool = redis.ConnectionPool(host='47.100.225.208', port=6379, password="Miluo@123", db=0, max_connections=10)
            self.redis_conn = redis.Redis(connection_pool=self.pool, decode_responses=True)
            self.netConvert = "D:\sumo\\bin\\netconvert.exe"
            self.BASE_NET_FILE = 'net/20250213.net.xml'

        elif env == 'prod':
            ##SUMO linux version 1.21.0.
            self.pool = redis.ConnectionPool(host='47.100.225.208', port=6379, password="Miluo@123", db=0, max_connections=10)
            self.redis_conn = redis.Redis(connection_pool=self.pool, decode_responses=True)
            self.netConvert = "D:\sumo\\bin\\netconvert.exe"
            self.BASE_NET_FILE = 'net/20250213.net.xml'

        elif env == 'test':
            self.pool = redis.ConnectionPool(host='10.25.13.34', port=6379, password="Miluo@123", db=0, max_connections=10)
            self.redis_conn = redis.Redis(connection_pool=self.pool, decode_responses=True)
            self.netConvert = "/usr/local/share/sumo/bin/netconvert"
            self.BASE_NET_FILE = 'net/20250213.net.xml'

        elif env == 'test2':
            self.pool = redis.ConnectionPool(host='47.100.225.208', port=6379, password="Miluo@123", db=0, max_connections=10)
            self.redis_conn = redis.Redis(connection_pool=self.pool, decode_responses=True)
            self.netConvert = "/usr/local/share/sumo/bin/netconvert"
            self.BASE_NET_FILE = 'net/20250213.net.xml'

        logger.add(self.log_file, rotation="00:00", encoding="utf-8", retention='3 days')


